﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Diploma.Models;
using StudentEntity = Diploma.Models.Student;

namespace DiplomaWeb.Models.Reviewer
{
    public class StudentProgressViewModel
    {
        public IEnumerable<SelectListItem> Groups { get; private set; }

        public Guid Id { get; set; }
        public string FIO { get; set; }
        public bool Placement { get; set; }
        public bool AllPoints { get; set; }
        public bool ThemeWithOrder { get; set; }
        public bool Notice { get; set; }
        public bool Feedback { get; set; }
        public bool SignatureNormControl { get; set; }
        public bool PreliminaryPresentation { get; set; }
        public bool SignatureLecturer { get; set; }
        public bool SignatureStudent { get; set; }
        public bool SignatureConsultants { get; set; }
        public bool Slides { get; set; }
        public bool Archive { get; set; }

        public bool IsSaved { get; set; }

        public void ToViewModel(IEnumerable<StudentsGroup> studentsGroups)
        {
            Groups = studentsGroups.OrderBy(r => r.Name).Select(r => new SelectListItem
            {
                Text = r.Name,
                Value = r.StudentsGroupId.ToString()
            });
        }

        public void ToViewModel(StudentEntity student)
        {
            Id = student.UserId;
            FIO = student.FullName;
            if(student.CollaborationRoom != null)
            {
                var room = student.CollaborationRoom;
                Placement = room.Placement.HasValue && room.Placement.Value;
                ThemeWithOrder = room.ThemeWithOrder.HasValue && room.ThemeWithOrder.Value;
                Notice = room.Notice.HasValue && room.Notice.Value;
                Feedback = room.Feedback.HasValue && room.Feedback.Value;
                SignatureNormControl = room.SignatureNormControl.HasValue && room.SignatureNormControl.Value;
                PreliminaryPresentation = room.PreliminaryPresentation.HasValue && room.PreliminaryPresentation.Value;
                SignatureLecturer = room.SignatureLecturer.HasValue && room.SignatureLecturer.Value;
                SignatureStudent = room.SignatureStudent.HasValue && room.SignatureStudent.Value;
                SignatureConsultants = room.SignatureConsultants.HasValue && room.SignatureConsultants.Value;
                Slides = room.Slides.HasValue && room.Slides.Value;
                Archive = room.Archive.HasValue && room.Archive.Value;
                AllPoints = DataManager.Instance.StudentsRepository.IsAllPointSuccess(student.UserId);
            }
        }
    }
}